package usecase

import (
	"gitee.com/fx8s/goIrisTest/src/modules/profile/model"
	"gitee.com/fx8s/goIrisTest/src/modules/profile/repository"

	storyModel "gitee.com/fx8s/goIrisTest/src/modules/story/model"
	storyRepo "gitee.com/fx8s/goIrisTest/src/modules/story/repository"
)

type profileUsercaseImpl struct {
	profileRepository repository.ProfileRepository
	storyRepository   storyRepo.StoryRepository
}

func NewProfileUsercase(profileRepository repository.ProfileRepository, storyRepository storyRepo.StoryRepository) *profileUsercaseImpl {
	return &profileUsercaseImpl{
		profileRepository: profileRepository,
		storyRepository:   storyRepository,
	}
}

func (profileUsercase *profileUsercaseImpl) SaveStory(entity *storyModel.Story) (*storyModel.Story, error) {
	err := profileUsercase.storyRepository.Save(entity)
	if err != nil {
		return nil, err
	}
	return entity, nil
}

func (profileUsercase *profileUsercaseImpl) SaveProfile(profile *model.Profile) (*model.Profile, error) {
	err := profileUsercase.profileRepository.Save(profile)
	if err != nil {
		return nil, err
	}
	return profile, nil
}

func (profileUsercase *profileUsercaseImpl) UpdateProfile(id string, profile *model.Profile) (*model.Profile, error) {
	err := profileUsercase.profileRepository.Update(id, profile)
	if err != nil {
		return nil, err
	}
	return profile, nil
}

func (profileUsercase *profileUsercaseImpl) GetById(id string) (*model.Profile, error) {
	profile, err := profileUsercase.profileRepository.FindById(id)
	if err != nil {
		return nil, err
	}
	return profile, nil
}

func (profileUsercase *profileUsercaseImpl) GetByEmail(email string) (*model.Profile, error) {
	profile, err := profileUsercase.profileRepository.FindByEmail(email)
	if err != nil {
		return nil, err
	}
	return profile, nil
}
